<%@ page import="java.io.InputStream" %>
<%@ page import="java.util.Base64" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2025/10/20
  Time: 10:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<img src="/img/1.jpg" alt="" width="200px">

<%
    // 使用pageContext获取servletContext
    ServletContext context = pageContext.getServletContext();
    // 读取resources中的图片
    InputStream inputStream = context.getResourceAsStream("/WEB-INF/classes/imgs/1.jpg");
    String imageBase64 = "";
    if (inputStream != null) {
        byte[] bytes = inputStream.readAllBytes();
        imageBase64 = Base64.getEncoder().encodeToString(bytes);
    }
%>
<img src="data:image/jpeg;base64, <%= imageBase64 %>" alt="图片">
</body>
</html>
